﻿using System;
using System.Configuration;
using System.Xml;

namespace EmbeddedSharp.Scripting {
    /// <summary>
    /// ms-help://MS.MSDNQTR.v90.en/enu_kbaspnetkb/aspnetkb/309045.htm#1
    /// </summary>
    public class SectionHelper {
        public static XmlNode GetEnumValue
            (XmlNode _node, string _attribute, Type _enumType, ref int _val) {
            XmlNode a = _node.Attributes.RemoveNamedItem(_attribute);
            if (a == null)
                throw new ConfigurationErrorsException(
                    "Attribute required: " + _attribute);
            if (Enum.IsDefined(_enumType, a.Value))
                _val = (int)Enum.Parse(_enumType, a.Value);
            else
                throw new ConfigurationErrorsException("Invalid Level", a);
            return a;
        }
        
        public static XmlNode GetStringValue(
            XmlNode _node, string _attribute, ref string _val) {
            XmlNode a = _node.Attributes.RemoveNamedItem(_attribute);
            if (a == null)
                throw new ConfigurationException(
                    "Attribute required: " + _attribute);
            else
                _val = a.Value;
            return a;
        }

    }
}
